import {sm2} from "sm-crypto";

const global_publicKey = ""
const global_privateKey = ""

function sm2Decrypt(data, privateKey) {
    if (!privateKey) {
        privateKey = global_privateKey;
    }
    return sm2.doDecrypt(data, privateKey)
}

function sm2Encrypt(data, publicKey) {
    if (!publicKey) {
        publicKey = global_publicKey;
    }
    return sm2.doEncrypt(data, publicKey)
}

function sm2CreateKey() {
    let generateKeyPairHex = sm2.generateKeyPairHex();
    let result = {}
    result.publicKey = generateKeyPairHex.publicKey;
    result.privateKey = generateKeyPairHex.privateKey;
    return result;
}


const smTools = {}
smTools.sm2Decrypt = sm2Decrypt
smTools.sm2Encrypt = sm2Encrypt
smTools.sm2CreateKey = sm2CreateKey
export default smTools
